package com.github.data_manage.util

import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.lang.Nullable

/**
 * @author 18066
 * @since 2020/11/11
 */
object PageUtil {
    /**
     * 获取分页号
     *
     * @param pageNum 用户传入的分页号
     */
    @JvmStatic
    fun buildPageNum(@Nullable pageNum: Int?): Int {
        return pageNum ?: 1
    }

    /**
     * 获取分页大小
     *
     * @param pageSize 用户传入的分页大小
     */
    @JvmStatic
    fun buildPageSize(@Nullable pageSize: Int?): Int {
        return pageSize ?: 10
    }


    fun <T> buildJpaPage(
        @Nullable pageNum: Int?,
        @Nullable pageSize: Int?
    ): PageRequest {
        return PageRequest.of(buildPageNum(pageNum) - 1, buildPageSize(pageSize))
    }


}